﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_GetAccessPermission]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_GetAccessPermission];
GO
CREATE PROCEDURE [dbo].[sproc_GetAccessPermission]
    @Class_ID int,
    @Username nvarchar(50),
    @Act_ID int,
    @ReturnValue int output
/*

========================================================
功能:得到用户@Username对对象@Class_ID是否又@Act_ID权
参数:
    @Class_id int        :    组（类）ID
备注:可以优化
========================================================

*/
AS
BEGIN
SET NOCOUNT ON

    DECLARE @allowAccess bit;

    exec dbo.sproc_GetRightInPositionToHandleClass
        @ClassID = @Class_ID,
        @Username = @Username,
        @Act_ID = @Act_ID,
        @AllowAccess = @allowAccess output;
    if ( @AllowAccess = 1 )
        goto HAS_PERMISSION;


    exec dbo.sproc_GetRightInTeamToHandleClass
        @ClassID = @Class_ID,
        @Username = @Username,
        @Act_ID = @Act_ID,
        @AllowAccess = @allowAccess output;
    if ( @AllowAccess = 1 )
        goto HAS_PERMISSION;

    exec dbo.sproc_GetRightInRoleToHandleClass
        @ClassID = @Class_ID,
        @Username = @Username,
        @Act_ID = @Act_ID,
        @AllowAccess = @allowAccess output;
    if ( @AllowAccess = 1 )
        goto HAS_PERMISSION;

    exec dbo.sproc_GetRightInPersonToHandleClass
        @ClassID = @Class_ID,
        @Username = @Username,
        @Act_ID = @Act_ID,
        @AllowAccess = @allowAccess output;
    if ( @AllowAccess = 1 )
        goto HAS_PERMISSION;

    -- The user does not have the requested permission.
    SET @ReturnValue = 0;
    RETURN 0;

HAS_PERMISSION:
    SET @ReturnValue = 1;
    RETURN 1;

END
GO